package com.wxx.找不同;

import java.util.HashSet;
import java.util.Set;

/**
 * @author: Jetwang
 * @date: 2022/4/5 22:17
 * @description: Solution package com.wxx.找不同;
 * @version: 1.0
 */
public class Solution {
    public static char findTheDifference(String s, String t) {
        if (s.length() == 0) {
            return t.charAt(0);
        }
        int num01 = 0, num02 = 0;
        for (int i = 0; i < s.length(); i++) {
            num01 += s.charAt(i);
        }
        for (int i = 0; i < t.length(); i++) {
            num02 += t.charAt(i);
        }
        return (char)(num02 - num01);
    }

    /**
     * 异或方法
     * @param s
     * @param t
     * @return
     */
    public static char findTheDifference02(String s, String t) {
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            res ^= s.charAt(i);
        }
        for (int i = 0; i < t.length(); i++) {
            res ^= t.charAt(i);
        }
        return (char)res;
    }

    public static void main(String[] args) {
        char theDifference = findTheDifference("abcd", "abcde");
        System.out.println(theDifference);
        char theDifference01 = findTheDifference("", "y");
        System.out.println(theDifference01);

        char theDifference02 = findTheDifference02("abcd", "abcde");
        System.out.println(theDifference02);
        char theDifference03 = findTheDifference02("", "y");
        System.out.println(theDifference03);
    }
}
